/*
 * Copyright 2002-2006 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.sharkburner.app.views;

import java.awt.BorderLayout;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

import org.springframework.richclient.application.support.AbstractView;

public class MainView extends AbstractView {

	protected JComponent createControl() {
		JPanel panel = getComponentFactory().createPanel(new BorderLayout());

		/* Init drawing */
		JScrollPane categoryScrollPanel = getComponentFactory()
				.createScrollPane();
		JTree categoryTree = generateCategoryTreeNodes();

		JPanel headPanel = getComponentFactory().createPanel();
		JSeparator separatorTop = new javax.swing.JSeparator();
		JPanel contentPanel = getComponentFactory().createPanel();
		JPanel footerPanel = getComponentFactory().createPanel();

		/* set size on load */
		panel.setPreferredSize(new java.awt.Dimension(600, 400));

		categoryScrollPanel.setViewportView(categoryTree);

		headPanel.setBackground(new java.awt.Color(255, 255, 255));
		headPanel.setPreferredSize(new java.awt.Dimension(470, 50));

		javax.swing.GroupLayout headPanelLayout = new javax.swing.GroupLayout(
				headPanel);
		headPanel.setLayout(headPanelLayout);
		headPanelLayout.setHorizontalGroup(headPanelLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0,
				Short.MAX_VALUE));
		headPanelLayout.setVerticalGroup(headPanelLayout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 50,
				Short.MAX_VALUE));

		javax.swing.GroupLayout contentPanelLayout = new javax.swing.GroupLayout(
				contentPanel);
		contentPanel.setLayout(contentPanelLayout);
		contentPanelLayout.setHorizontalGroup(contentPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 0, Short.MAX_VALUE));
		contentPanelLayout.setVerticalGroup(contentPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 0, Short.MAX_VALUE));

		footerPanel.setBackground(new java.awt.Color(204, 204, 204));
		footerPanel.setPreferredSize(new java.awt.Dimension(0, 50));

		javax.swing.GroupLayout footerPanelLayout = new javax.swing.GroupLayout(
				footerPanel);
		footerPanel.setLayout(footerPanelLayout);
		footerPanelLayout.setHorizontalGroup(footerPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 470, Short.MAX_VALUE));
		footerPanelLayout.setVerticalGroup(footerPanelLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 50, Short.MAX_VALUE));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(panel);
		panel.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addComponent(categoryScrollPanel,
										javax.swing.GroupLayout.PREFERRED_SIZE,
										233,
										javax.swing.GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														headPanel,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(separatorTop)
												.addComponent(
														contentPanel,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(
														footerPanel,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														470, Short.MAX_VALUE))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														categoryScrollPanel,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														704, Short.MAX_VALUE)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		headPanel,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		separatorTop,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		contentPanel,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																.addComponent(
																		footerPanel,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)))
								.addContainerGap()));
		/*  */

		return panel;
	}

	/**
	 * Generate category tree all items are situated inner
	 * <root>/ui/message.properties file
	 * */
	private JTree generateCategoryTreeNodes() {

		DefaultMutableTreeNode root = new DefaultMutableTreeNode(
				getComponentFactory().createLabel("departments.root").getText());
		DefaultMutableTreeNode bar = new DefaultMutableTreeNode(
				getComponentFactory().createLabel("departments.item1")
						.getText());
		root.insert(bar, 0);
		DefaultMutableTreeNode bucatarie = new DefaultMutableTreeNode(
				getComponentFactory().createLabel("departments.item2")
						.getText());
		root.insert(bucatarie, 1);

		return new JTree(root);
	}
}
